import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

// const COVER_URL = [
//   require('@/components/music-player/assets/cover.jpg'),
//   require('@/components/music-player/assets/cover2.jpg'),
//   require('@/components/music-player/assets/cover3.jpg')
// ]

export default new Vuex.Store({
  state: {
    // 默认播放状态
    isPlaying: false,
    musicModel: [],
    playList: [],
    finCurrent: null,
    coverUrl: '',
    songsInfo: '',
  },
  mutations: {
    togglePlay(state, toggle) {
      state.isPlaying = toggle !== undefined ? toggle : !state.isPlaying
    },
    updateMusicModel(state, payload) {
      state.musicModel = payload;
    },
    updatePlayList(state, payload) {
      state.playList.push(payload)
    },
    updateFinCurrent(state, payload) {
      state.finCurrent += payload
    },
    changeCover(state, payload) {
      const model = state.musicModel.filter(item => item.id == payload)
      state.coverUrl = model[0].al.picUrl
    },
    changeSongsInfo(state, payload) {
      const model = state.musicModel.filter(item => item.id == payload)
      let name = model[0].name ? model[0].name : model[0].al.name
      // 艺人名
      let arName = model[0].ar[0].name
      state.songsInfo = name + ' - ' + arName
    }
  },
  actions: {
  },
  modules: {
  }
})
